home *** CD-ROM | disk | FTP | other *** search
- /*
- "mic_data_path.cpp"
-
- This file contains Mic-1 objects which fall in the "data path" catagory, such as
- the ScratchPad, ALU, and shifter. Also defined is the common register.
- */
-
- #include <iostream.h>
- #include <fstream.h>
- #include <iomanip.h>
-
- #include "mic_main.h"
- #include "mic_memory.h"
- #include "mic_data_path.h"
- #include "mic_control.h"
-
- #pragma mark ••• MAR •••
-
- void MARClass::output (Mic_1_Class& Mic)
- {
- Mic.Memory.input_MAR(Mic, word);
- }
-
- ostream& operator << (ostream& s, MARClass& m)
- {
- s << hex << uppercase;
- s << "MAR:" << endl;
- s << " ADDR: " << setw(4) << setfill('0') << right << m.word << endl;
- s << " ENABLED: " << m.mar_enabled << endl;
- s << resetiosflags(ios::hex | ios::uppercase);
- return s;
- }
-
- #pragma mark ---------------------------------
- #pragma mark ••• MBR •••
-
- void MBRClass::input_Memory (unsigned short newWord)
- {
- if (read_enabled)
- word = newWord;
- }
-
- void MBRClass::input_Shifter (unsigned short newWord)
- {
- if (mbr_enabled)
- word = newWord;
- }
-
- void MBRClass::output (Mic_1_Class& Mic)
- {
- if (write_enabled)
- Mic.Memory.input_MBR(Mic, word);
- //if (read_enabled)
- Mic.AMUX.input_MBR(Mic, word);
- }
-
- ostream& operator << (ostream& s, MBRClass& m)
- {
- s << hex << uppercase;
- s << "MBR:" << endl;
- s << " MBR WORD: " << setw(4) << setfill('0') << right << m.word << endl;
- s << " READ: " << m.read_enabled << endl;
- s << " WRITE: " << m.write_enabled << endl;
- s << " ENABLED: " << m.mbr_enabled << endl;
- s << resetiosflags(ios::hex | ios::uppercase);
- return s;
- }
-
- #pragma mark ---------------------------------
- #pragma mark ••• SCRATCHPAD •••
-
- ScratchPadClass::ScratchPadClass()
- {
- registers[0] = 0; // PC
- registers[1] = 0; // AC
- registers[2] = 0; // SP
- registers[3] = 0; // IR
- registers[4] = 0; // TIR
- registers[5] = 0; // 0
- registers[6] = 1; // +1
- registers[7] = -1; // -1
- registers[8] = 0x0FFF; // AMASK
- registers[9] = 0x00FF; // SMASK
- registers[10] = 0; // A
- registers[11] = 0; // B
- registers[12] = 0; // C
- registers[13] = 0; // D
- registers[14] = 0; // E
- registers[15] = 0; // F
-
- shifter_word = 0;
- selection_a = 0;
- selection_b = 0;
- selection_c = 0;
- c_enabled = false;
- }
-
- void ScratchPadClass::output (Mic_1_Class& Mic)
- {
- Mic.A_Latch.input_ScratchPad(registers[selection_a]);
- Mic.B_Latch.input_ScratchPad(registers[selection_b]);
- }
-
- ostream& operator << (ostream& s, ScratchPadClass& scratch)
- {
- s << hex << uppercase;
- s << "SCRATCHPAD:" << endl;
- s << " INPUT WORD: " << setw(4) << setfill('0') << right << scratch.shifter_word << endl;
- s << resetiosflags(ios::hex | ios::uppercase);
- s << " SELECTION A: " << scratch.selection_a << endl;
- s << " SELECTION B: " << scratch.selection_b << endl;
- s << " SELECTION C: " << scratch.selection_c << endl;
- s << " LOAD ENABLED: " << scratch.c_enabled << endl;
- s << " REGISTERS:" << endl;
- s << hex << uppercase;
- for (int i=0; i<16; i++)
- s << " " << i << " " << setw(4) << setfill('0') << right << scratch.registers[i] << endl;
- s << resetiosflags(ios::hex | ios::uppercase);
- return s;
- }
-
- #pragma mark ---------------------------------
- #pragma mark ••• AMUX •••
-
- void AMUXClass::output (Mic_1_Class& Mic)
- {
- if (from_mbr)
- Mic.ALU.input_AMUX(Mic, mbr_word);
- else
- Mic.ALU.input_AMUX(Mic, a_latch_word);
- }
-
- ostream& operator << (ostream& s, AMUXClass& a)
- {
- s << "AMUX:" << endl;
- s << " MBR WORD: " << setw(4) << setfill('0') << right << a.mbr_word << endl;
- s << " A_LATCH WORD: " << setw(4) << setfill('0') << right << a.a_latch_word << endl;
- s << " SWITCH (0=A_LATCH, 1=MBR): " << a.from_mbr << endl;
- s << resetiosflags(ios::hex | ios::uppercase);
- return s;
- }
-
- #pragma mark ---------------------------------
- #pragma mark ••• ALU •••
-
- void ALUClass::output (Mic_1_Class& Mic)
- {
- unsigned short word = 0;
-
- switch (operation)
- {
- case (0): word = amux_word + b_latch_word; break; // A + B
- case (1): word = amux_word & b_latch_word; break; // A & B
- case (2): word = amux_word; break; // A
- case (3): word = ~amux_word; break; // not A
- }
- if ((word >> 15) == 1)
- negative = true;
- else
- negative = false;
-
- if (word == 0)
- zero = true;
- else
- zero = false;
-
- Mic.MicroSeq.input_negative(negative);
- Mic.MicroSeq.input_zero(Mic, zero);
- Mic.Shifter.input_ALU(Mic, word);
- }
-
- ostream& operator << (ostream& s, ALUClass& a)
- {
- s << hex << uppercase;
- s << "ALU:" << endl;
- s << " AMUX WORD: " << setw(4) << setfill('0') << right << a.amux_word << endl;
- s << " B_LATCH WORD: " << setw(4) << setfill('0') << right << a.b_latch_word << endl;
- s << " OPERATION: " << a.operation << endl;
- s << " NEGATIVE: " << a.negative << endl;
- s << " ZERO: " << a.zero << endl;
- s << resetiosflags(ios::hex | ios::uppercase);
- return s;
- }
-
- #pragma mark ---------------------------------
- #pragma mark ••• SHIFTER •••
-
- void ShifterClass::input_ALU (Mic_1_Class& Mic, unsigned short newWord)
- {
- word = newWord;
- switch (option)
- {
- case (0): break; // do nothing
- case (1): word >>= 1; break; // shift right 1 bit
- case (2): word <<= 1; break; // shift left 1 bit
- }
- output(Mic);
- }
-
- void ShifterClass::output (Mic_1_Class& Mic)
- {
- Mic.MBR.input_Shifter(word);
- Mic.ScratchPad.input_Shifter(word);
- }
-
- ostream& operator << (ostream& s, ShifterClass& a)
- {
- s << hex << uppercase;
- s << "SHIFTER: " << endl;
- s << " WORD: " << setw(4) << setfill('0') << right << a.word << endl;
- s << " OPTION: " << a.option << endl;
- s << resetiosflags(ios::hex | ios::uppercase);
- return s;
- }
-
- #pragma mark ---------------------------------
- #pragma mark ••• A_LATCH •••
-
- void A_LatchClass::output (Mic_1_Class& Mic)
- {
- Mic.AMUX.input_A_Latch(Mic, word);
- }
-
- ostream& operator << (ostream& s, A_LatchClass& a)
- {
- s << hex << uppercase;
- s << "A LATCH: " << setw(4) << setfill('0') << right << a.word << endl;
- s << resetiosflags(ios::hex | ios::uppercase);
- return s;
- }
-
- #pragma mark ---------------------------------
- #pragma mark ••• B_LATCH •••
-
- void B_LatchClass::output (Mic_1_Class& Mic)
- {
- Mic.MAR.input_B_Latch(word);
- Mic.ALU.input_B_Latch(Mic, word);
- }
-
- ostream& operator << (ostream& s, B_LatchClass& b)
- {
- s << hex << uppercase;
- s << "B LATCH: " << setw(4) << setfill('0') << right << b.word << endl;
- s << resetiosflags(ios::hex | ios::uppercase);
- return s;
- }